from django.contrib import admin
from django.http import HttpResponse
from django.shortcuts import render
from myweb.models import MyUser
# Register your models here.
#########################################################################################
def login(request):
    if request.method != "POST":
        return HttpResponse('Error in Login!')
    user = request.POST.get('userid', None)
    psw = request.POST.get('password', None)

    if user is None or psw is None:
        return HttpResponse('用户名或密码输入格式出错!<a href="#" onclick="javascript:history.back(-1);">返回上一页！</a>')
    print('登陆信息：', user, '__', psw)
    try:
        users = MyUser.objects.get(username=user, password=psw)

        print(users, users.username, users.times)

        import datetime
        users.times = users.times + 1
        users.logindate = datetime.datetime.now() #str(datetime.datetime.now())
        users.save()
    except:
        return HttpResponse('用户名或密码不匹配!<br/> 请重新登录！<br/><a href="#" onclick="javascript:history.back(-1);">返回上一页！</a>')
    else:
        return render(request, 'myweb/detectImages.html')
        # return render(request, 'myweb/detectImage.html')

def testImages(request):
    return render(request, 'myweb/detectImages.html')


